//
//  YZMTMainViewController.swift
//  YZMweibo
//
//  Created by Simon on 16/4/18.
//  Copyright © 2016年 Simon. All rights reserved.
//

import UIKit

class YZMTMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        //初始化tabbar 
        
        let tabbar = YZMTabbar()
        tabbar.barDele = self
        
        // 通过kvc
        setValue(tabbar, forKey: "tabBar")
        //
        addChildViewController(YZMHomeTableViewController(), imageName: "tabbar_home", title: "主页")
        addChildViewController(YZMDiscoverTableViewController(), imageName: "tabbar_discover", title: "发现")
        addChildViewController(YZMMessiageTableViewController(), imageName: "tabbar_message_center", title: "消息")
        addChildViewController(YZMProfileTableViewController(), imageName: "tabbar_profile", title: "我的")
        
        // Do any additional setup after loading the view.
    }
    // 添加子控制器方法
    func addChildViewController(childController: UIViewController,imageName: String,title: String) {
        //设置图片
        childController.tabBarItem.image = UIImage(named: imageName)
        //设置选中图片
        childController.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")
        //设置title
        childController.title = title
        //添加控制器
        addChildViewController(UINavigationController(rootViewController:childController))
    }
}

extension YZMTMainViewController:YZMTabbarDelegate{
    func compbuttonClick() {
        let composeVc = YZMComposeViewController()
        presentViewController(UINavigationController(rootViewController: composeVc), animated: true, completion: nil)
    }
}

